//
//  SingleDeftailViewController.m
//  悠狸
//
//  Created by dllo on 15/9/1.
//  Copyright (c) 2015年 Dung. All rights reserved.
//

#import "SingleDeftailViewController.h"
#import "SingleModel.h"
#import "UIImageView+WebCache.h"
#import "SingleDetail.h"
#import "DB.h"
#import "NovelDataBase.h"
#import "ShopModel.h"
#import "UMSocial.h"

@interface SingleDeftailViewController ()<UITableViewDataSource,UITableViewDelegate,SingleDetailDelegate,UMSocialUIDelegate>
@property (nonatomic, retain)UITableView *table;
@end

@implementation SingleDeftailViewController

- (void)dealloc
{
    [_table release];
    [_model release];
    [super dealloc];
}
- (instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
    }
    return self;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    self.navigationController.navigationBar.translucent = NO;

    self.title = @"商品详情";
    
    [self create];
}
- (void)create
{
    self.table = [[[UITableView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height ) style:UITableViewStylePlain] autorelease];
    _table.delegate =self;
    _table.dataSource =self;

    _table.rowHeight = self.view.frame.size.height;
    [self.view addSubview:_table];

    [_table registerClass:[SingleDetail class] forCellReuseIdentifier:@"i"];
    
    UIView *bview = [[[UIView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width , 60 *OffHeight)] autorelease];
    bview.backgroundColor = [UIColor cyanColor];
   bview.userInteractionEnabled = YES;
    [self.view addSubview:bview];
    
    UIButton *abutton = [[[UIButton alloc] initWithFrame:CGRectMake(60*OffWidth, 10*OffHeight, 100*OffWidth, 30*OffHeight)] autorelease];
    [abutton setTitle:@"收藏" forState:UIControlStateNormal];
    [abutton setTitleColor:[UIColor redColor] forState: UIControlStateNormal];
    [bview addSubview:abutton];
    [abutton addTarget:self action:@selector(collection) forControlEvents:UIControlEventTouchUpInside];
    
    UIButton *bbutton = [[[UIButton alloc] initWithFrame:CGRectMake(200*OffWidth, 10*OffHeight, 100*OffWidth, 30*OffHeight)] autorelease];
    [bbutton setTitle:@"分享" forState:UIControlStateNormal];
    [bbutton setTitleColor:[UIColor redColor] forState: UIControlStateNormal];
    [bview addSubview:bbutton];
    [bbutton addTarget:self action:@selector(share:) forControlEvents:UIControlEventTouchUpInside];
    
    
}
//- (void)collection
//{
//    [DB dbOpen];
//    
//    ShopModel *model = [[[ShopModel alloc] initwithld:self.model.Id name:self.model.name favorites_count:self.model.favorites_count cover_image_url:self.model.cover_image_url price:self.model.price url:self.model.url] autorelease];
//   
//    [NovelDataBase twoinsertWithModel:model];
//    
//}
- (void)share:(UIButton *)button
{
    [UMSocialSnsService presentSnsIconSheetView:self
                                         appKey:@"55e85cb9e0f55af6ba0061c1"
                                      shareText:self.model.url
                                     shareImage:nil
                                shareToSnsNames:[NSArray arrayWithObjects:UMShareToTencent, nil]
                                       delegate:self];
    NSLog(@"!!!!!!!=====%@",self.model.url);
}
- (void)sendValue:(NSInteger)height
{
    _table.rowHeight = height;
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 1;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    SingleDetail *cell = [tableView dequeueReusableCellWithIdentifier:@"i" forIndexPath:indexPath];
//    cell.model = self.model;
    cell.delegate = self;
    [cell sendVallue:self.model];
    return cell;
}

//隐藏tabbar
- (void)viewWillAppear:(BOOL)animated
{
    self.tabBarController.tabBar.hidden = YES;
}
//显示tabbar
- (void)viewWillDisappear:(BOOL)animated
{
    self.tabBarController.tabBar.hidden = NO;
}
@end
